package io;

import java.io.*;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        //向文件pw.txt中写入文本数据
        /*
            PrintWriter提供了直接对文件进行写操作的构造器:
            PrintWriter(String filename)
            PrintWriter(File file)
            上述两个构造器内部都进行了4层流连接
            PrintWriter->BufferedWriter->OutputStreamWriter->FileOutputStream
            PW:负责按行写出字符串
            BW:块写文本数据加速(内部有一个默认8192长度的字符数组)
            OSW:将写出的字符转字节
            FOS:将字节写入到文件中

         */

        FileOutputStream fos=new FileOutputStream("pw.txt");
        OutputStreamWriter osw=new OutputStreamWriter(fos);
        BufferedWriter bw=new BufferedWriter(osw);
//        PrintWriter pw=new PrintWriter(bw);
//        pw.println("你好");
//        pw.println("再见");
//        pw.close();
        PrintWriter pw=new PrintWriter(bw,true);
        Scanner scan=new Scanner(System.in);
        System.out.println("开始输出内容，exit退出");
        while (true){
            String line=scan.nextLine();
            if ("exit".equalsIgnoreCase(line)){
                break;
            }
                pw.println(line);
        }
        pw.close();


    }
}
